package com.njupt.StackAndQueue;

import java.util.Stack;

public class MyQueue {

    Stack<Integer> stackIn;
    Stack<Integer> stackOut;

    public MyQueue() {
        stackIn = new Stack<Integer>();
        stackOut = new Stack<Integer>();
    }

    public void push(int x) {
        stackIn.push(x);
    }

    public int pop() {
        if(!stackOut.empty()){
            return stackOut.pop();
        }else {
            while(!stackIn.empty()){
                stackOut.push(stackIn.pop());
            }
            return stackOut.pop();
        }

    }

    public int peek() {
        if(!stackOut.empty()){
            return  stackOut.peek();
        }else {
            while(!stackIn.empty()){
                stackOut.push(stackIn.pop());
            }
            return stackOut.peek();
        }
    }

    public boolean empty() {
        if(!stackIn.empty() || !stackOut.empty()){
            return  false;
        }
        return true;
    }

    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1);
        myQueue.push(2);

    }
}
